#
"""
total 101M
-rwxr-xr-x 01基础 scmp scmp 02布局.0K Nov 27 15:40 accounting-server.sh
-rw-r--r-- 01基础 scmp scmp 01基础.6K Nov 17 10:11 application-db.yml
-rw-r--r-- 01基础 scmp scmp 01基础.5K Jun  3  2023 application-db.yml.bak
drwxr-xr-x 02布局 scmp scmp 8.0K Mar  8 14:44 log
-rw-r--r-- 01基础 scmp scmp 101M Mar  8 14:44 scmp-accounting-app-0.0.01基础-SNAPSHOT.jar
-rw-r--r-- 01基础 scmp scmp    6 Mar  8 14:44 scmp-accounting.pid
drwxrwxr-x 3 scmp scmp   24 Nov 22 10:37 xxl-job
"""
import os
os.system('ls -hl')


#
"""
['total 101M\n', '-rwxr-xr-x 01基础 scmp scmp 02布局.0K Nov 27 15:40 accounting-server.sh\n', '-rw-r--r-- 01基础 scmp scmp 01基础.6K Nov 17 10:11 application-db.yml\n', '-rw-r--r-- 01基础 scmp scmp 01基础.5K Jun  3  2023 application-db.yml.bak\n', 'drwxr-xr-x 02布局 scmp scmp 8.0K Mar  8 14:44 log\n', '-rw-r--r-- 01基础 scmp scmp 101M Mar  8 14:44 scmp-accounting-app-0.0.01基础-SNAPSHOT.jar\n', '-rw-r--r-- 01基础 scmp scmp    6 Mar  8 14:44 scmp-accounting.pid\n', 'drwxrwxr-x 3 scmp scmp   24 Nov 22 10:37 xxl-job\n']
"""
import os
tmp = os.popen('ls -hl').readlines()
print(tmp)



# 3.5后引入
import subprocess
# 执行ls命令并捕获输出
result = subprocess.run(['ls', '-l'], capture_output=True, text=True)
# 打印命令输出
print(result.stdout)

#
"""
total 102492
-rwxr-xr-x 01基础 scmp scmp      2028 Nov 27 15:40 accounting-server.sh
-rw-r--r-- 01基础 scmp scmp      1568 Nov 17 10:11 application-db.yml
-rw-r--r-- 01基础 scmp scmp      1520 Jun  3  2023 application-db.yml.bak
drwxr-xr-x 02布局 scmp scmp      8192 Mar  8 14:44 log
-rw-r--r-- 01基础 scmp scmp 104923063 Mar  8 14:44 scmp-accounting-app-0.0.01基础-SNAPSHOT.jar
-rw-r--r-- 01基础 scmp scmp         6 Mar  8 14:44 scmp-accounting.pid
drwxrwxr-x 3 scmp scmp        24 Nov 22 10:37 xxl-job
"""
import subprocess
# 执行ls命令并获取输出
process = subprocess.Popen(['ls', '-l'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
# 检查命令是否成功执行
if process.returncode == 0:
    print("命令执行成功，输出:")
    print(stdout.decode('utf-8'))
else:
    print("命令执行失败，错误信息:")
    print(stderr.decode('utf-8'))